run-lints.ts 944 B

1234567891011121314151617181920212223242526272829
  1. import { NextApiRequest, NextApiResponse } from 'next'
  2. import { constructHeaders } from '@/lib/api/apiHelpers'
  3. import apiWrapper from '@/lib/api/apiWrapper'
  4. import { DEFAULT_EXPOSED_SCHEMAS } from '@/lib/api/self-hosted/constants'
  5. import { getLints } from '@/lib/api/self-hosted/lints'
  6. export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)
  7. async function handler(req: NextApiRequest, res: NextApiResponse) {
  8. const { method } = req
  9. switch (method) {
  10. case 'GET':
  11. const { data, error } = await getLints({
  12. headers: constructHeaders(req.headers),
  13. exposedSchemas: DEFAULT_EXPOSED_SCHEMAS,
  14. })
  15. if (error) {
  16. return res.status(400).json(error)
  17. } else {
  18. return res.status(200).json(data)
  19. }
  20. default:
  21. res.setHeader('Allow', ['GET'])
  22. res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
  23. }
  24. }